from Common.MTurk.BaseParams import BaseParams

class CreateHITParams(BaseParams):
    """
        Data Module for create HIT request
    """
    
    # default value for non-required parameters is None
    # default value for required parameters must be some value except None is default value in MTurk API
    def __init__(self, question, lifetimeInSeconds=-1, maxAssignments=-1, requesterAnnotation="", hitTypeID='', 
                 title='Test HIT Creation', description='This is a default value for HIT creation request', 
                 reward=[{'Amount':0.01, 'CurrencyCode':'USD'}], 
                 assignmentDurationIn=None, keywords=None, autoApprovalDelayInSeconds=None, qualificationRequirement=None):
        BaseParams.__init__(self, 'CreateHIT') #operation
        
        self.parameters["Question"]=question
        
        if -1 != lifetimeInSeconds:
            self.parameters["LifetimeInSeconds"]=lifetimeInSeconds # any integer between 30 (30 seconds) and 31536000 (365 days).
        
        if -1 != maxAssignments:
            self.parameters["MaxAssignments"]=maxAssignments # any integer between 1 and 1000000000 (1 billion).
            
        if '' != requesterAnnotation:
            self.parameters['RequesterAnnotation']=requesterAnnotation # must not be longer than 255 characters
            
        
        if '' != hitTypeID:
            # create HIT with HIT Type Id
            self.parameters['HITTypeId'] = hitTypeID
        else:
            # create HIT without HIT Type Id
            self.parameters['Title'] = title # must not be more than 128 characters
            self.parameters['Description'] = description # cannot be more than 2,000 characters in length
            if None != assignmentDurationIn:
                self.parameters['AssignmentDurationIn'] = assignmentDurationIn # any integer between 30 (30 seconds) and 31536000 (365 days)
            if None != keywords:
                self.parameters['Keywords'] = keywords
            if None != autoApprovalDelayInSeconds:
                self.parameters['AutoApprovalDelayInSeconds'] = autoApprovalDelayInSeconds
            # TODO: Handle Reward in CreateHITParams
            #if None != reward:
            #    for i in reward.
            # TODO: Handle qualificationRequirement in CreateHITParams
        
"""
Operation, Question, LifetimeInSeconds, MaxAssignments, RequesterAnnotation, HITTypeId
"""
   
"""
Operation, Question, LifetimeInSeconds, MaxAssignments, RequesterAnnotation, Title, Description, Reward, AssignmentDurationIn, 
Keywords, AutoApprovalDelayInSeconds, QualificationRequirement
"""

if __name__ == "__main__":
    chp = CreateHITParams('TestOperation')
    print chp.parameters
